<?php

namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;

use app\services\CreativeService;
use app\services\TanxService;

class CreativeSyncController extends AuthController
{
    public $currentHeader = 'header-sync';
    public $currentNav = 'creative-sync-nav';
    public $pageTitle = '';

    public function init() {
        parent::init();
        $this->service = new CreativeService();
    }

    public function actionSyncList() {
        $this->pageTitle = $this->t('sync', 'Creative Syncronization List');
        return $this->show();
    }

    public function actionListOperateHandle() {
        $id = $this->I('creative_id');
        if ($this->I('id') == 1) {   //ssp创意同步
            $result = $this->service->uploadCreative($id); 
            $result = $this->service->updateCreative($id); 
        }
        $this->OK($this->t('sync', 'Creative Syncronized!'));
    }

    public function actionGetAdNetwork() {
        $data = $this->service->getAll('AdNetwork', ['status' => 1]);
        $matrix = [
            'id' => 'id',
            'channel' => ['name', '$v=="vamaker"&&$v=\Yii::t("resource", "ValueMaker");
                                    return $v;'],
            'period' => ['id', 'return \Yii::t("sync", "4 times per hour");'],
            'operate' => ['id', 'return "refresh";'],
        ];
        $data = $this->fieldsMap($matrix, $data);
        $this->jsonReturn(['data' => $data]);
    }
    
}//end
